<!DOCTYPE html>
<html>
	<head>
		<#include "/templates/commons/head.html">
		<script type="text/javascript">
			/**
			*点击保存按钮保存页面信息
			*/
			function save(){
			  	if(!$("#addForm").validateForm()){
					return;
			   	}
			    var method = document.addForm.method.value;
				var messages = "";
				if(method=="addSave"){
					messages = "您是否确定要添加？";
				}else if(method=="editSave"){
					messages = "您是否确定要修改？";
				}
				layer.confirm(messages, {
					    btn: ['确定', '取消']
					}, function() {
					    document.addForm.action = "${ctx!}/DemoController/" + method + ".do";
						document.addForm.submit();
					}, function() {
				});
			}
			/**
			*点击保存按钮保存页面信息
			*/
			function dialogSave(_callback){
			  	if(!$("#addForm").validateForm()){
					return;
			   	}
			    var method = document.addForm.method.value;
				var messages = "";
				if(method=="addSave"){
				    method = "dialogAddSave";
					messages = "您是否确定要添加？";
				}else if(method=="editSave"){
				    method = "dialogEditSave";
					messages = "您是否确定要修改？";
				}
				layer.confirm(messages, {
					    btn: ['确定', '取消']
					}, function() {
					    ajaxSubmit(document.addForm, "${ctx}/DemoController/" + method + ".do", _callback);
					    /* document.addForm.action = "${ctx}/DemoController/" + method + ".do";
						document.addForm.submit();
						_callback(); */
					}, function() {
				});
			}
			/**
			*点击返回按钮进入用户列表页面
			*/
			function goBack(){
				document.addForm.action = "${ctx}/DemoController/queryList.do";
				document.addForm.submit();
			}
			
			function chooseDialog() {
				Common.chooseDocument(0, "", function(res) {
				    console.log(res);
				    //赋值
				    $("#imgPath").val(res[0].fileId);//或者
				    $("#imgPath").val(res[0].path);
				    //变更按钮样式
				    $(".upload-btn").addClass("upload-btn-finish");
				    //展示样式
				    $("#LAY_upload").attr("src", res[0].pathShow).removeClass("fn-hide");
				    $(".file-name").text(res[0].fileName);
				});
		    }
			
			function openDialog() {
			    layer.open({
					type: 2,
					title: '选择页面',
					shade: 0.4, //弹窗后边是否显示阴影 可以填true/false 或者0.？透明度
					shadeClose: true,//点击阴影是否关闭弹窗
					maxmin: true, //开启最大化最小化按钮
					btn: ['确定','关闭'],
					area: [document.body.clientWidth * 0.6 + "px", document.body.clientWidth * 0.6 / 1.5 + "px"],
					offset: (document.body.clientHeight - 570) / 2,//高度
					content: ctx + '/DemoController/dialogList.do',
					yes: function(index){
			        	//当点击‘确定’按钮的时候，获取弹出层返回的值
					    var iframeWin = window["layui-layer-iframe" + index];
			        	var res = iframeWin.callbackdata();
			        	if (res) {
			        	    $(".chooseDialog").text(res[0].id);
			        	    $("#dialogId").val(res[0].id);
				        	layer.close(index);
			        	}
			    	}
				});
			}
			
			/*
			 *	使用ready()方法替代$(function() {}) 和 $(document).ready(function() {}) 以及 window.onload 等初始化方法
			 */
			function ready() {
			    //省市联动
			    var cityCodePath = "<@city cityPath="${demoBean.city!''}">${cityPath}</@city>";
			    Common.initCity(cityCodePath);
			};
		</script>
	</head>
	<body>
		<div id="div-body" class="body addPage">
			<div class="hid-scroller-body">
				<!-- 标题 Start -->
				<#include "/templates/commons/menuPath.html">
				<!-- 标题 End -->
				<form id="addForm" modelAttribute="demoBean" name="addForm" method="post" class="layui-form">
					<!-- list页面搜索条件 Start -->
					<input type="hidden" name="param_keyword" value="${Request.param_keyword!}"/>
					<input type="hidden" name="id" value="${demoBean.id!}"/>
					<!-- list页面搜索条件 End -->
					<!-- add||edit页面信息Start -->
					<#if method=='add'>
						<input type="hidden" name="method" value="addSave"/>
					<#else>
						<input type="hidden" name="method" value="editSave"/>
					</#if>
					<!-- add||edit页面信息End -->
					<!-- 添加信息 Form Start -->
					<div class="main-container">
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>选择类型</label>
							<div class="layui-input-inline">
								<select name="type">
									<option value="">-请选择-</option>
									<@dict type="role_type">
										<#list dictList as dict>
											<option value="${dict.code}" <#if (demoBean.type?? && demoBean.type == dict.code)>selected</#if>>${dict.name}</option>
										</#list>
									</@dict>
								</select>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">省市</label>
							<div class="layui-input-inline">
								<select name="province" id="province" lay-filter="changeRegions">
									<option value="">-请选择省份-</option>
									<@city pcityCode="0">
										<#list cityList as item>
											<option value="${item.code}">${item.name}</option>
										</#list>
									</@city>
								</select>
							</div>
							<div class="layui-input-inline">
								<select name="city" id="city">
									<option value="">-请选择-</option>
								</select>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>单选</label>
							<div class="layui-input-block">
								<@dict type="yes_no">
									<#if dictList??>
										<#list dictList as dict>
											<input type="radio" name="radio" value="${dict.code}" title="${dict.name}" <#if (demoBean.radio?? && demoBean.radio == dict.code)>checked</#if>>
										</#list>
									</#if>
								</@dict>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>多选</label>
							<div class="layui-input-block">
								<#if demoBean.checkbox??>
									<#assign checkbox = demoBean.checkbox?split(',') />
								<#else>
									<#assign checkbox = []/>
								</#if>
								<@dict type="role_type">
									<#if dictList??>
										<#list dictList as dict>
											<input type="checkbox" name="checkbox" value="${dict.code}" title="${dict.name}" <#if checkbox??>${checkbox?seq_contains(dict.code!)?string("checked", "")}</#if>>
										</#list>
									</#if>
								</@dict>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>内容</label>
							<div class="layui-input-block">
								<input name="context" isValidate="true" notEmpty="true" class="layui-input" placeholder="普通输入框使用layui-input-block" value="${demoBean.context!}"/>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">备注</label>
							<div class="layui-input-block">
								<textarea name="remark" placeholder="请输入备注" class="layui-textarea">${demoBean.remark!}</textarea>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>弹窗</label>
							<div class="layui-input-inline">
								<span class="layui-input chooseDialog" onclick="openDialog();">点击选择id</span>
								<input type="hidden" name="dialogId" id="dialogId" value="${demoBean.dialogId!}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>日期</label>
							<div class="layui-input-inline">
								<input name="date" value="${demoBean.date!}" readonly="true" isValidate="true" notEmpty="true" placeholder="请选择日期" autocomplete="off" class="layui-input" layuidate="true"/>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"><span class="redSpan">*</span>时间</label>
							<div class="layui-input-inline">
								<input name="datetime" value="${demoBean.datetime!}" readonly="true" isValidate="true" notEmpty="true" placeholder="请选择日期时间" autocomplete="off" class="layui-input" layuidatetime="true"/>
							</div>
						</div>
						<link rel="stylesheet" href="${ctx!}/styles/document-management.css" media="all" />
						<div class="layui-form-item">
							<label class="layui-form-label">选择图片</label>
							<div class="layui-input-block">
								<div class="site-demo-upload upload-file-btn-group">
									<#if (demoBean.img?? && demoBean.img != '')>
										<#assign var_class = 'fn-show' />
									<#else>
										<#assign var_class = 'fn-hide' />
									</#if>
									<img id="LAY_upload" src="${demoBean.imgShow!}" class="${var_class}">
									<span class="file-name"></span>
									<button type="button" class="layui-btn layui-btn-xs layui-btn-danger upload-btn <#if (demoBean.img?? && demoBean.img != '')>upload-btn-finish</#if>" onclick="chooseDialog();"><i class="layui-icon">&#xe67c;</i>上传图片</button>
								</div>
								<input type="hidden" name="img" value="${demoBean.img!}" id="imgPath">
							</div>
						</div>
					</div>
					<!-- 添加信息 Form End -->
					<!-- 按钮区域 Start -->
					<div class="main-button">
						<div class="layui-input-block">
							<#if ((Session.CUR_MENU.addRole==1 && method=='add') || (Session.CUR_MENU.updateRole==1 && method=='edit'))>
								<button type="button" class="layui-btn" onClick="save();"><i class="layui-icon">&#xe642;</i>保存</button>
							</#if>
							<button type="button" class="layui-btn layui-btn-primary" onClick="goBack();"><i class="layui-icon">&#xe65c;</i>返回</button>
						</div>
					</div>
					<!-- 按钮区域 End -->
				</form>
			</div>
		</div>
	</body>
</html>